import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Manage',
    component: () => import('../views/Manage.vue'),
    redirect:"/Login",
    children: [
      {path: 'home', name: 'Home', component: () => import('../views/system/Home.vue')},
      {path: 'user', name: 'User', component: () => import('../views/system/User.vue')},

      {path: 'role', name: 'Role', component: () => import('../views/system/Role.vue')},
      {path: 'menu', name: 'Menu', component: () => import('../views/system/Menu.vue')},

      {path: 'File', name: 'File', component: () => import('../views/system/File.vue')},

      {path: 'data', name: 'Data', component: () => import('../views/system/Data.vue')},

      {path: 'person', name: 'Person', component: () => import('../views/system/Person.vue')},
      // {path: 'data', name: 'Data', component: () => import('../views/tools/Data.vue')},

      {path: 'Hot', name: 'Hot', component: () => import('../views/tools/Hot.vue')},
      {path: 'ScatterDiagram', name: 'ScatterDiagram', component: () => import('../views/tools/ScatterDiagram.vue')},
      {path: 'Scatter', name: 'Scatter', component: () => import('../views/tools/Scatter.vue')},

      {path: 'ThreeDimensional', name: 'ThreeDimensional', component: () => import('../views/tools/ThreeDimensional.vue')},

      {path: 'Grid', name: 'Grid', component: () => import('../views/tools/Grid.vue')},
      {path: 'Svector', name: 'Svector', component: () => import('../views/tools/Svector.vue')},

      {path: 'taxiTrace', name: 'taxiTrace', component: () => import('../views/tools/taxiTrace.vue')},

      {path: 'HighAccuracyHot', name: 'HighAccuracyHot', component: () => import('../views/tools/HighAccuracyHot.vue')},

      {path: 'Aggregation', name: 'Aggregation', component: () => import('../views/tools/Aggregation.vue')},
      {path: 'Zone', name: 'Zone', component: () => import('../views/tools/Zone.vue')},
      {path: 'AddShapefile', name: 'AddShapefile', component: () => import('../views/tools/AddShapefile.vue')},
      {path: 'odflyline', name: 'odflyline', component: () => import('../views/tools/ODFlyLine')},
    ]
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
  },
  {
    path: '/register',
    name: 'register',
    component: () => import('../views/Register.vue'),
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 路由守卫
router.beforeEach((to, from, next) => {

  localStorage.setItem("currentPathName", to.name)  // 设置当前的路由名称，为了在Header组件中去使用
  store.commit("setPath")  // 触发store的数据更新
  next()  // 放行路由
})

// beforeRouteLeave(to, from, next){
//   this.$destroy();
//   next();
// }



export default router
